package com.itheima.health.dao;

import com.github.pagehelper.Page;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 2024/7/8-10:51
 * 功能:
 */
public interface SetMealMapper {
    @Insert("insert into t_setmeal values (null, #{name}, #{code}, #{helpCode}, #{sex}, #{age}, #{price}, #{remark}, #{attention}, #{img});")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Setmeal setmeal);
    @Insert("insert into t_setmeal_checkgroup values (#{setmeal_id}, #{checkgroup_id});")
    void setSetmealAndCheckGroup(Map<String, Integer> map);

    Page<Setmeal> findPage(String queryString);
    @Select("select * from t_setmeal  where id=#{id};")
    Setmeal findById(Integer id);
    @Select("select checkgroup_id from t_setmeal_checkgroup where setmeal_id = #{setmealId};")
    List<Integer> findCheckGroupIdsBySetmealId(String setmealId);

    void edit(Setmeal setmeal);
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{id)};")
    void deleteAssociation(Integer id);
    @Insert("insert into t_setmeal_checkgroup values (#{setmeal_id}, #{checkgroup_id});")
    void setSetmealAndCheckgroup(Map<String, Integer> map);
    @Select("select * from t_setmeal;")
    List<Setmeal> findAll();
    @Results({@Result(property = "checkGroups", column = "id", many = @Many(select = "com.itheima.health.dao.CheckGroupDao.findBySetmealId"))
    })
    @Select("select * from t_setmeal where id=#{id}")
    Setmeal findFullSetmealById(Integer id);


}
